#coding=utf-8
# #第四节课作业
import re   # 导入re模块

def get_list(txt):
    f = open(txt)
    words = []
    for line in f:
        line = line.strip()             # 去空格回车
        _words = line.lower().split(' ')    # 分割
        for w in _words:
            if not w.isalpha():                 # 包含非字母
                w = re.sub('[^a-zA-Z]', '', w)  # 去除非字母
            if len(w.strip()) != 0:             # 保证不是空内容
                words.append(w)
    words.sort()
    lista = []
    for i in set(words):
        w = i + ' ' + str(words.count(i))
        lista.append(w)
    return lista


def write_txt(lista,txt):
    f = open(txt, 'w')
    lista.sort()
    for a in lista:
        f.write('%s\n' % a)
    f.close()






get_list('license.txt')
write_txt(get_list('license.txt'),'output.txt')

